/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import React, { useRef, useState } from 'react';
import DragTable from '@/components/DragTable';
import ProTable from '@ant-design/pro-table';
import type { ActionType } from '@ant-design/pro-table';
import { kbTypeOptions, FormColFormat, AccountInfo, columns } from '../index.config';
import { handQuery } from '@/services/Finance/transfer';
import { Button, Form, Input, message, Select } from 'antd';
import styles from './index.less';

const FormItem = Form.Item;
const Index = () => {
  const actionRef = useRef<ActionType>();
  const [dataSource, setDataSoutce] = useState<{
    in: AccountInfo[] | any[];
    out: AccountInfo[] | any[];
  }>({ in: [], out: [] });

  const getLogList = async (values: any) => {
    handQuery(values).then((res) => {
      const { code, data, msg } = res;
      if (code == 0) {
        setDataSoutce(data);
      } else {
        message.error(msg);
      }
    });
  };
  return (
    <div>
      <Form
        layout='horizontal'
        {...FormColFormat}
        initialValues={{ kb_type: 's' }}
        onFinish={getLogList}
      >
        <FormItem name='kb_type' label='账号类型'>
          <Select options={kbTypeOptions} />
        </FormItem>
        <FormItem name='username' label='账号'>
          <Input placeholder='请输入账号' />
        </FormItem>
        <FormItem label=' ' colon={false}>
          <Button htmlType='submit' type='primary'>
            查询
          </Button>
        </FormItem>
      </Form>
      <DragTable>
        <ProTable
          cardProps={{
            title: '出账查询',
            style: { marginTop: 24 },
          }}
          rowKey='id'
          className={styles.detailTable}
          actionRef={actionRef}
          dataSource={dataSource.out}
          pagination={false}
          columns={columns}
          options={false}
          search={false}
          scroll={{ x: 700 }}
        />
      </DragTable>
      <DragTable>
        <ProTable
          cardProps={{
            title: '入账查询',
            style: { marginTop: 24 },
          }}
          rowKey='id'
          className={styles.detailTable}
          options={false}
          search={false}
          pagination={false}
          dataSource={dataSource.in}
          columns={columns}
          scroll={{ x: 700 }}
        />
      </DragTable>
    </div>
  );
};

export default Index;
